home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / amok_lha / amok49.lha / Speech / txt / Speech.mod next >
Text File  |  1993-08-15  |  6KB  |  195 lines

  1. (*----------------------------------------------------------------------------
  2.  
  3.    :Program.    Speech.mod
  4.    :Author.     Franz Dimbeck
  5.    :Address.    Troppauerstr. 48
  6.    :Adress.     8058 Erding
  7.    :Phone.      08122 18135
  8.    :Copyright.  Freeware
  9.    :Language.   Oberon
  10.    :Translator. Oberon V1.17.1 A+L AG  Fridtjof Siebert
  11.    :Contents.   Routinen zur Sprachunterstützung mit Ausgabe der Mundform.
  12.    :Support.    Speech Modula-2 [mif]
  13.    :History.    V1.0 Mai 1990 mit Mundausgabe Modula-2 Franz Dimbeck
  14.    :History.    V1.1 23-Nov-1990 Oberon Franz Dimbeck
  15.    :Remark.     Wer übersetzt die TGerman-Prozedur des Moduls Speech (M2)
  16.    :Remark.      von Michael Frieß [mif] nach OBERON ?
  17.  
  18. -----------------------------------------------------------------------------*)
  19.  
  20.  
  21. MODULE Speech;
  22.  
  23.  
  24. IMPORT
  25.   Sys: SYSTEM,
  26.   D  : Dos,
  27.   E  : Exec,
  28.   ES : ExecSupport,
  29.   N  : Narrator,
  30.   Str: Strings,
  31.   R  : Requests,
  32.   Translator,
  33.   NoGuruRq;
  34.  
  35.  
  36.  
  37. TYPE
  38.      voice* = RECORD
  39.               rate*, pitch*, mode*,
  40.               sex*, volume*, sampFreq*,
  41.               channels*: INTEGER;
  42. (*
  43.  :note. rate     Range: 40..400                 default: 150
  44.  :note. pitch    Range: 65..320                 default: 110
  45.  :note. mode     Range: 0=natural, 1=robotic    default: 0
  46.  :note. sex      Range: 0=male, 1=feamle        default: 0
  47.  :note. volume   Range: 0..64                   default: 64
  48.  :note. sampFreq Range: 5000..28000             default: 22200
  49.  :note. channels Range: 0=both, 1=left, 2=right default: 0
  50. *)
  51.              END;
  52.  
  53.  
  54. VAR DefaultVoice* : voice;
  55.  
  56.     MouthProc*    : PROCEDURE(Width,Height:INTEGER);
  57.  (* :note. MouthProc is a procedure supplied by you, wich does something
  58.     :note. with the mouthinformations Width:INTEGER and Height:INTEGER,
  59.     :note. e.g. draws different mouthshapes.
  60.     :note. When SayPhonemes is started, MouthProc executes repeatedly
  61.     :note. until Narrator stops speaking.
  62.  
  63.  *)
  64.  
  65.  
  66. CONST module = "Speech";
  67.       readP  = "ReadMouth";
  68.  
  69. VAR WritePort,
  70.     ReadPort      : E.MsgPortPtr;
  71.     WriteNarrator : N.NarratorPtr;
  72.     ReadNarrator  : N.MouthPtr;
  73.     BothChannels  : ARRAY 4 OF BYTE;
  74.     RightChannels : ARRAY 2 OF BYTE;
  75.     LeftChannels  : ARRAY 2 OF BYTE;
  76.  
  77. PROCEDURE OpenNarrator ;
  78.  BEGIN
  79.   WritePort := NIL; WriteNarrator := NIL;
  80.   WritePort := ES.CreatePort (Sys.ADR(module), 0);
  81.   R.Assert((WritePort # NIL),"WritePort klemmt");
  82.   WriteNarrator  := ES.CreateExtIO (WritePort, Sys.SIZE (N.Narrator));
  83.   R.Assert((WriteNarrator # NIL),"WriteNarrator klemmt");
  84.    WriteNarrator.message.command := E.write;
  85.    WriteNarrator.chMasks := Sys.ADR(BothChannels);
  86.    WriteNarrator.nmMasks := 4;
  87.   IF  E.OpenDevice (N.narratorName, 0, WriteNarrator, LONGSET{0})#0 THEN END;
  88.   WriteNarrator^.mouths := 1;
  89.   ReadPort := NIL; ReadNarrator := NIL;
  90.   ReadPort := ES.CreatePort (NIL, 0);
  91.   R.Assert((ReadPort # NIL),"ReadPort klemmt");
  92.   ReadNarrator  := ES.CreateExtIO (ReadPort, Sys.SIZE (N.Mouth));
  93.   R.Assert((ReadNarrator # NIL),"ReadNarrator klemmt");
  94.     ReadNarrator.voice                           := WriteNarrator^;
  95.     ReadNarrator.voice.message.error             := 0;
  96.     ReadNarrator.voice.message.command           := E.read;
  97.     ReadNarrator.voice.message.message.replyPort := ReadPort;
  98.     ReadNarrator.voice.message.message.length    := Sys.SIZE(N.Mouth);
  99.     ReadNarrator.width  := 0;
  100.     ReadNarrator.height := 0;
  101.  END OpenNarrator;
  102.  
  103. PROCEDURE CloseNarrator;
  104. BEGIN
  105.   IF (ReadNarrator  # NIL) THEN ES.DeleteExtIO (ReadNarrator) END;
  106.   IF (ReadPort      # NIL) THEN ES.DeletePort  (ReadPort) END;
  107.   IF (WriteNarrator # NIL) THEN
  108.     E.CloseDevice (WriteNarrator);
  109.     ES.DeleteExtIO (WriteNarrator)
  110.   END;
  111.   IF (WritePort     # NIL) THEN ES.DeletePort  (WritePort) END;
  112. END CloseNarrator;
  113.  
  114.  
  115. PROCEDURE SayPhonemes* (p: ARRAY OF CHAR; v: voice);
  116. VAR i : INTEGER;
  117.  BEGIN
  118.    WriteNarrator.rate   := v.rate;
  119.    WriteNarrator.pitch  := v.pitch;
  120.    WriteNarrator.mode   := v.mode;
  121.    WriteNarrator.sex    := v.sex;
  122.    WriteNarrator.volume := v.volume;
  123.    WriteNarrator.sampFreq := v.sampFreq;
  124.    IF (v.channels=1) THEN
  125.      WriteNarrator.chMasks := Sys.ADR(LeftChannels);
  126.      WriteNarrator.nmMasks := 2;
  127.    ELSIF (v.channels=2) THEN
  128.      WriteNarrator.chMasks := Sys.ADR(RightChannels);
  129.      WriteNarrator.nmMasks := 2;
  130.    ELSE
  131.      WriteNarrator.chMasks := Sys.ADR(BothChannels);
  132.      WriteNarrator.nmMasks := 4;
  133.    END;
  134.    WriteNarrator.message.data   := Sys.ADR(p);
  135.    WriteNarrator.message.length := Str.Length (p);
  136.   IF (MouthProc#NIL) THEN
  137.     WriteNarrator^.mouths := 1;
  138.     E.SendIO(WriteNarrator);
  139.     E.DoIO(ReadNarrator);
  140.     i:=1;
  141.     REPEAT
  142.     INC(i);
  143.       REPEAT
  144.         MouthProc(Sys.VAL(SHORTINT,ReadNarrator^.width),
  145.                   Sys.VAL(SHORTINT,ReadNarrator^.height));
  146.  
  147.         E.DoIO(ReadNarrator);
  148.       UNTIL  (ReadNarrator^.voice.message.error = N.noWrite);
  149.     UNTIL i>10;
  150.     E.WaitIO(WriteNarrator);
  151.   ELSE
  152.     E.DoIO(WriteNarrator);
  153.   END;
  154.  END SayPhonemes;
  155.  
  156.  
  157.  
  158. PROCEDURE Translate* (in: ARRAY OF CHAR; VAR out: ARRAY OF CHAR) : LONGINT;
  159. BEGIN
  160.   RETURN Translator.Translate
  161.   (Sys.ADR(in), Str.Length(in), Sys.ADR(out), LEN(out)-1);
  162. END Translate;
  163.  
  164. PROCEDURE Say* (EnglishString: ARRAY OF CHAR);
  165.   VAR
  166.     Phonemes : ARRAY 1024 OF CHAR;
  167.     Result   : LONGINT;
  168. BEGIN
  169.   Result := Translate(EnglishString,Phonemes);
  170.   SayPhonemes(Phonemes, DefaultVoice);
  171. END Say;
  172.  
  173. BEGIN
  174.   MouthProc := NIL;
  175.   OpenNarrator;
  176.   BothChannels[0] := 3;
  177.   BothChannels[1] := 5;
  178.   BothChannels[2] := 10;
  179.   BothChannels[3] := 12;
  180.   LeftChannels[0] := 1;
  181.   LeftChannels[1] := 8;
  182.   RightChannels[0] := 2;
  183.   RightChannels[1] := 4;
  184.   DefaultVoice.rate := N.defRate;
  185.   DefaultVoice.pitch  := N.defPitch;
  186.   DefaultVoice.mode   := N.defMode;
  187.   DefaultVoice.sex    := N.defSex;
  188.   DefaultVoice.volume := N.defVol;
  189.   DefaultVoice.sampFreq := N.defFreq;
  190.   DefaultVoice.channels := 0;
  191. CLOSE
  192.  CloseNarrator;
  193. END Speech.
  194.  
  195.